<template>
	<view class="content">
		<QSInput layout="column" :tapClear=false :name="formName" variableName="type"  title="链接类型" v-model="type" :itemDisabled="true"></QSInput>
		<QSInput layout="column" :name="formName" variableName="ewallet"  title="钱包地址" v-model="values.ewallet" :itemDisabled="itemDisabled">dfasdfas</QSInput>
		<QSInput layout="column" :name="formName" variableName="phone"  title="手机号码" ifCode v-model="values.phone" :itemDisabled="itemDisabled" @getCode="getCode">dfasdfas</QSInput>
		<QSInput layout="column" :name="formName" variableName="smscode"  title="验证码" v-model="values.smscode" :itemDisabled="itemDisabled">dfasdfas</QSInput>
		<QSInput layout="column" :name="formName" variableName="account"  title="帐号" v-model="values.account" :itemDisabled="itemDisabled">dfasdfas</QSInput>
		<QSInput layout="column" :name="formName" variableName="name"  title="名称" v-model="values.name" :itemDisabled="itemDisabled">dfasdfas</QSInput>
		<QSInput layout="column" :name="formName" variableName="bank"  title="开户行" v-model="values.bank" :itemDisabled="itemDisabled">dfasdfas</QSInput>
		<button type="primary" @tap="bangding">绑定</button>
	</view>
</template>

<script>
	import {
		getHyPayment,
		postHyPayment,
		putHyPayment
	} from '@/services/user.service.js'
	export default {
		components: {
			
		},
		data() {
			return {
				formName: 'input',
				link:'',
				itemDisabled: false,
				type:'',
				values:{},
				id:0,
				token:'',
				phone:''
			}
		},
		onLoad(option) {
			var  that=this;
			that.type = option.type;
			that.id = option.id;  //如果id 为null 新增 否则是修改
		},
		onShow(){
			this.checkToken();
		},
	
		methods: {
			getCode () {
				
			},
			checkToken(){
				var that=this;
				 uni.getStorage({
				    key: 'token',
				    success: function (res) {
						that.token=res.data;
						that.getAccount(res.data);
				    },
					fail:function(error){
						uni.navigateTo({
							url: `/pages/login/login`
						})
					}});
			},
			//如果id有，先查用户的帐户信息
			async getAccount(token){
				if(this.id!=0){
					const {data} = await getHyPayment({key: this.id});
					this.values = data;
				}
			},
			
			//绑定提交
			async bangding(){
				
				console.log(this.values);
				var url="";
				console.log(this.token);
				if(this.id==0) //新增/core/api/v1/hy/payment
				{
					this.$set(this.values,'type',this.type);
					const  {data} = await postHyPayment(this.values);
				}
				else  //修改 /core/api/v1/hy/payment/{id}
				{
					this.values.key = this.id;
					const {data} = await putHyPayment(this.values);
					
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	$color-primary: #12B3F9;
	.content {
		display: flex;
		flex-direction: column;
		// align-items: center;
		// justify-content: center;
		// background-color: #F2F2F2;
	}
	
	button[type="primary"]{
		background-color: $color-primary;
		border-radius: 0;
		font-size: 34upx;
		margin-top: 60upx;
		width: 80%;
		border-radius: 40upx;
	}
</style>
